package com.xia.department.controller;


import com.xia.department.entity.Department;
import com.xia.department.service.DepartmentService;
import com.xia.handler.UserException;
import com.xia.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xia
 * @since 2020-10-20
 */

@RestController
@RequestMapping("/department")
@Api(value = "部门模块", tags = "部门模块")
@CrossOrigin
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;


    @GetMapping("/findDeptAndCount")
    @ApiOperation(value = "查询部门",notes = "查询部门")
    public Result findDeptAndCount(){
        List<Department> deptAndCountList = departmentService.findDeptAndCount();

        if (deptAndCountList.size() < 1){
            throw new UserException(20003,"未查询到数据");
        }
        return Result.ok().data("departments",deptAndCountList);
    }



}

